<?php

function get_observation_form($observation, $isValidate) {
  $path = drupal_get_path('module','win_observation');
  drupal_add_js($path . '/js/external/jquery.form.js');
  drupal_add_js($path . '/js/external/jtip.js');
  drupal_add_css($path . '/css/jtip/global.css');
  drupal_add_css($path . '/css/jquery-ui.css');

  $observation_id = 0;
  if ($observation !== NULL) {
    $observation_id = $observation->id;
  }

  if ($isValidate != NULL) {
    drupal_add_js('var isValidate = 1;', 'inline');
  }

  $cn_languages = get_common_name_languages();

  $gender_options = array(t(''),t('Male'), t('Female'), t('Hermaphrodite'), t('Not Applicable'), t('Not Sure'));
  $pod_options = get_part_of_day_options();
  $waterbody_type_list = array(t('Lake'), t('River'), t('Ocean'));

  $basis_of_record_list = get_basis_of_record_list();

  $taxanomic_status_list = get_taxanomic_status_list();
  $nomenclature_type_status_list = get_nomenclature_type_status_list();

  $countries_list = get_countries_list();

  $lifestage_list = array(t(''),t('Adult'), t('Embryo'), t('Gamete'), t('Gametophyte'), t('Juvenile'), t('Larva'), t('Spore'), t('Sporophyte'), t('Zygote'), t('Not sure'));

  require_once('win_observation_ecosystems.inc');
  $parent_ecosystems_list = get_parent_ecosystems(TRUE);

  $nativeness_list = get_nativeness_list();
  $iucn_threat_category_list = get_iucn_threat_category_list();

  $synonym_reasons = get_synonym_reasons();

  $observers_list = get_observers_list();
  //$observers_list[0] = 'New';

  $show_spell = 'style="display:block;"';
  if ($observation != NULL) {
    if (strtolower($observation->common_names[0]['cn_language']) == 'english') {
      $show_spell = 'style="display:none;"';
    }
  }

  $base_path = base_path();

  $html = '';
  $html .= '<form action="' . $base_path . 'observation/submit' . '"  accept-charset="UTF-8" method="post" id="win_getobservations">';
  $html .= '  <div>';
  $html .= '    <fieldset class=" collapsible">';
  $html .= '      <legend>' .  t('Common Names') . '</legend>';
  $html .= '      <fieldset class=" collapsible">';
  $html .= '        <legend>' .  t('Common Name') . '</legend>';
  $html .= '        <div class="form-item" id="edit-wo-common-name-wrapper">';
  $html .= '          <div style="width:140px; float: left;">';
  $html .= '            <label for="edit-wo-common-name">';
  $html .= '              ' .  t('Common Name') . ': ';
  $html .= '              <span class="form-required" title="' .  t('This field is required.') . '">*</span>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/common_name?width=375" class="jTip" id="tooltip_common_name" name="Common name:">?</a></span>';
  $html .= '            </label>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input title="Enter common name" type="text" maxlength="128" name="wo_common_name" id="edit-wo-common-name" size="30" value="' . get_text_observation_value($observation, 'common_name') . '" class="form-text required" />';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter common name.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-common-name-language-wrapper">';
  $html .= '          <div style="width:140px; float: left;">';
  $html .= '            <label for="edit-wo-common-name-language">';
  $html .= '              ' .  t('Language of common name') . ': ';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/common_name_language?width=375" class="jTip" id="tooltip_common_name_language" name="Language in which this common name is used:">?</a></span>';  $html .= '          </div>';
  $html .= '            </label>';
  $html .= '          <div>';
  //$html .= '            <input title="Enter the language of the common name" type="text" maxlength="128" name="wo_common_name_language" id="edit-wo-common-name-language" size="30" value="' . get_text_observation_value($observation, 'common_name_language') . '" class="form-text" />';
  $html .= '            <select name="wo_common_name_language" class="form-select" id="edit-wo-common-name-language" >';
  $html .= '              ' .  createDropdownOptions($cn_languages, $observation, 'cn_language') . '';
  $html .= '            </select>';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Select the language of the common name.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-common-name-region-wrapper">';
  $html .= '          <div style="width:140px; float: left;">';
  $html .= '            <label for="edit-wo-common-name-region" class="same-line">';
  $html .= '              ' . t('Region') . ': ';
  $html .= '              <span class="form-required" title="' .  t('This field is required.') . '">*</span>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/common_name_region?width=375" class="jTip" id="tooltip_common_name_region" name="Region where common name is used:">?</a></span>';
  $html .= '            </label>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input title="Enter the region where the common name is used." type="text" maxlength="128" name="wo_common_name_region" id="edit-wo-common-name-region" size="30" value="' . get_text_observation_value($observation, 'common_name_region') . '" class="form-text" />';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter the region where the common name is used.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-common-name-gender-wrapper">';
  $html .= '          <div style="width:140px; float: left;">';
  $html .= '            <label for="edit-wo-common-name-gender" class="same-line">' .  t('Gender') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/gender?width=375" class="jTip" id="tooltip_gender" name="gender:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <select name="wo_common_name_gender" class="form-select" id="edit-wo-common-name-gender" >';
  $html .= '              ' .  createDropdownOptions($gender_options, $observation, 'gender') . '';
  $html .= '            </select>';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Please select the gender of specimen.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-lifestage-wrapper">';
  $html .= '          <div style="width:140px; float: left;">';
  $html .= '            <label for="edit-wo-lifestage" class="same-line">' .  t('Life Stage') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/life_stage?width=375" class="jTip" id="tooltip_life_stage" name="Life stage:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <select name="wo_common_name_lifestage" class="form-select" id="edit-wo-common-name-lifestage" >';
  $html .= '              ' .  createDropdownOptions($lifestage_list, $observation, 'lifestage') . '';
  $html .= '            </select>';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter the lifestage of the specimen observed.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-common-name-english-wrapper" '.$show_spell.'>';
  $html .= '          <div style="width:140px; float: left;">';
  $html .= '            <label for="edit-wo-common-name-english" class="same-line">';
  $html .= '              ' .  t('English Spelling of Common Name') . ': ';
  $html .= '              <span class="form-required" title="' .  t('This field is required.') . '">*</span>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/common_name_english?width=375" class="jTip" id="tooltip_common_name_english" name="English Spelling of Common Name:">?</a></span>';
  $html .= '            </label>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" maxlength="128" name="wo_common_name_english" id="edit-wo-common-name-english" size="30" value="' . get_text_observation_value($observation, 'common_name_english') . '" class="form-text required" />';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Please enter the english spelling of the common name.') . '</div>';
  $html .= '        </div>';
  $html .= '      </fieldset>';
  $html .= '      ' . show_more_common_names($observation->common_names, $cn_languages, $gender_options, $lifestage_list);
  $html .= '';
  $html .= '      <input id="btn_add_more_common_names" type="button" value="Add more common names" onclick="addMoreCommonNamesUI()" />';
  $html .= '    </fieldset>';
  $html .= '';
  $html .= '    <fieldset class=" collapsible collapsed"><legend>' .  t('Taxanomic Information') . '</legend>';
  $html .= '      <fieldset class="collapsible">';
  $html .= '        <legend>Scientific Name</legend>';
  $html .= '        <div class="form-item" id="edit-wo-scientific-name-wrapper">';
  $html .= '          <div style="width:140px; float: left;">';
  $html .= '            <label for="edit-wo-scientific-name" class="same-line">' .  t('Scientific Name') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/scientific_name?width=375" class="jTip" id="tooltip_scientific_name" name="Scientific name:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input title="Scientific name of the organism. e.g. Rana tigrina" type="text" maxlength="128" name="wo_scientific_name" id="edit-wo-scientific-name" size="30" value="' . get_text_observation_value($observation, 'scientific_name') . '" class="form-text alpha_space" />';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Scientific name of the organism. e.g. Rana tigrina.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-scientific-name-author-wrapper">';
  $html .= '          <div style="width:140px; float: left;">';
  $html .= '            <label for="edit-wo-scientific-name-author" class="same-line">' .  t('Author') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/author?width=375" class="jTip alpha_space" id="tooltip_author" name="Author:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input title="Authority of the species description." type="text" maxlength="128" name="wo_scientific_name_author" id="edit-wo-scientific-name-author" size="30" value="' . get_text_observation_value($observation, 'scientific_name_author') . '" class="form-text alpha_space" />';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Authority of the species description.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-scientific-name-year-wrapper">';
  $html .= '          <div style="width:140px; float: left;">';
  $html .= '            <label for="edit-wo-scientific-name-year" class="same-line">' .  t('Year') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/year?width=375" class="jTip" id="tooltip_year" name="Year:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input title="Year in which the species was first described." type="text" maxlength="128" name="wo_scientific_name_year" id="edit-wo-scientific-name-year" size="30" value="' . get_text_observation_value($observation, 'scientific_name_year') . '" class="form-text till_current_year" />';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Year in which the species was first described.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '      </fieldset>';
  $html .= '';
  $html .= '      <div>';
  $html .= '        <div id="edit-wo-kingdom-wrapper" class="form-item">';
  $html .= '          <div style="width:155px; float: left;">';
  $html .= '            <label for="edit-wo-kingdom" class="same-line">Kingdom: </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/kingdom?width=375" class="jTip" id="tooltip_kingdom" name="Kingdom:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" class="form-text form-autocomplete" value="' . get_text_observation_value($observation, 's_kingdom') . '" size="20" id="edit-wo-kingdom" name="wo_kingdom" maxlength="128" autocomplete="OFF"/>';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter Kingdom.') . '</div>';
  $html .= '        </div>';
  $html .= '        <input type="hidden" disabled="disabled" value="' . base_path() . 'observation/col/suggestName/Kingdom/" id="edit-wo-kingdom-autocomplete" class="autocomplete"/>';
  $html .= '      </div>';
  $html .= '';
  $html .= '      <div>';
  $html .= '        <div id="edit-wo-phylum-wrapper" class="form-item">';
  $html .= '          <div style="width:155px; float: left;">';
  $html .= '            <label for="edit-wo-phylum" class="same-line">Phylum: </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/phylum?width=375" class="jTip" id="tooltip_phylum" name="Phylum:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" class="form-text form-autocomplete" value="' . get_text_observation_value($observation, 's_phylum') . '" size="20" id="edit-wo-phylum" name="wo_phylum" maxlength="128" autocomplete="OFF"/>';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter phylum.') . '</div>';
  $html .= '        </div>';
  $html .= '        <input type="hidden" disabled="disabled" value="' . base_path() . 'observation/col/suggestName/Phylum/" id="edit-wo-phylum-autocomplete" class="autocomplete"/>';
  $html .= '      </div>';
  $html .= '';
  $html .= '      <div>';
  $html .= '        <div id="edit-wo-class-wrapper" class="form-item">';
  $html .= '          <div style="width:155px; float: left;">';
  $html .= '            <label for="edit-wo-class" class="same-line">Class: </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/class?width=375" class="jTip" id="tooltip_class" name="Class:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" class="form-text form-autocomplete" value="' . get_text_observation_value($observation, 's_class') . '" size="20" id="edit-wo-class" name="wo_class" maxlength="128" autocomplete="OFF"/>';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter class.') . '</div>';
  $html .= '        </div>';
  $html .= '        <input type="hidden" disabled="disabled" value="' . base_path() . 'observation/col/suggestName/Class/" id="edit-wo-class-autocomplete" class="autocomplete"/>';
  $html .= '      </div>';
  $html .= '';
  $html .= '      <div>';
  $html .= '        <div id="edit-wo-order-wrapper" class="form-item">';
  $html .= '          <div style="width:155px; float: left;">';
  $html .= '            <label for="edit-wo-order" class="same-line">Order: </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/order?width=375" class="jTip" id="tooltip_order" name="Order:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" class="form-text form-autocomplete" value="' . get_text_observation_value($observation, 's_order') . '" size="20" id="edit-wo-order" name="wo_order" maxlength="128" autocomplete="OFF"/>';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter order.') . '</div>';
  $html .= '        </div>';
  $html .= '        <input type="hidden" disabled="disabled" value="' . base_path() . 'observation/col/suggestName/Order/" id="edit-wo-order-autocomplete" class="autocomplete"/>';
  $html .= '      </div>';
  $html .= '';
  $html .= '      <div>';
  $html .= '        <div id="edit-wo-family-wrapper" class="form-item">';
  $html .= '          <div style="width:155px; float: left;">';
  $html .= '            <label for="edit-wo-family" class="same-line">Family: </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/family?width=375" class="jTip" id="tooltip_family" name="Family:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" class="form-text form-autocomplete" value="' . get_text_observation_value($observation, 's_family') . '" size="20" id="edit-wo-family" name="wo_family" maxlength="128" autocomplete="OFF"/>';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter family.') . '</div>';
  $html .= '        </div>';
  $html .= '        <input type="hidden" disabled="disabled" value="' . base_path() . 'observation/col/suggestName/Family/" id="edit-wo-family-autocomplete" class="autocomplete"/>';
  $html .= '      </div>';
  $html .= '';
  $html .= '      <div>';
  $html .= '        <div id="edit-wo-genus-wrapper" class="form-item">';
  $html .= '          <div style="width:155px; float: left;">';
  $html .= '            <label for="edit-wo-genus" class="same-line">Genus: </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/genus?width=375" class="jTip" id="tooltip_genus" name="Genus:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" class="form-text form-autocomplete" value="' . get_text_observation_value($observation, 's_genus') . '" size="20" id="edit-wo-genus" name="wo_genus" maxlength="128" autocomplete="OFF"/>';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter genus.') . '</div>';
  $html .= '        </div>';
  $html .= '        <input type="hidden" disabled="disabled" value="' . base_path() . 'observation/col/suggestName/Genus/" id="edit-wo-genus-autocomplete" class="autocomplete"/>';
  $html .= '      </div>';
  $html .= '';
  $html .= '      <div>';
  $html .= '        <div id="edit-wo-species-wrapper" class="form-item">';
  $html .= '          <div style="width:155px; float: left;">';
  $html .= '            <label for="edit-wo-species" class="same-line">Species: </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/species?width=375" class="jTip" id="tooltip_species" name="Species:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" class="form-text form-autocomplete" value="' . get_text_observation_value($observation, 's_species') . '" size="20" id="edit-wo-species" name="wo_species" maxlength="128" autocomplete="OFF"/>';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter species.') . '</div>';
  $html .= '        </div>';
  $html .= '        <input type="hidden" disabled="disabled" value="' . base_path() . 'observation/col/suggestName/Species/" id="edit-wo-species-autocomplete" class="autocomplete"/>';
  $html .= '      </div>';
  $html .= '';
  $html .= '      <div>';
  $html .= '        <div id="edit-wo-taxanomic-status-wrapper" class="form-item">';
  $html .= '          <div style="width:155px; float: left;">';
  $html .= '            <label for="edit-wo-taxanomic-status" class="same-line">Taxanomic Status: </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/taxanomic_status?width=375" class="jTip" id="tooltip_taxanomic_status" name="Taxanomic Status:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <select name="wo_taxanomic_status" class="form-select" id="edit-wo-taxanomic-status" >';
  $html .= '              ' .  createDropdownOptions($taxanomic_status_list, $observation, 'taxanomic_status') . '';
  $html .= '            </select>';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Select taxanomic status.') . '</div>';
  $html .= '        </div>';
  $html .= '      </div>';
  $html .= '';
  $html .= '      <div>';
  $html .= '        <div id="edit-wo-nomenclature-type-status-wrapper" class="form-item">';
  $html .= '          <div style="width:155px; float: left;">';
  $html .= '            <label for="edit-wo-nomenclature-type-status" class="same-line">Nomenclature Type Status: ';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/nomenclature_type_status?width=375" class="jTip" id="tooltip_nomenclature_type_status" name="Nomencalture Type:">?</a></span></label>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <select name="wo_nomenclature_type_status" class="form-select" id="edit-wo-nomenclature-type-status" >';
  $html .= '              ' .  createDropdownOptions($nomenclature_type_status_list, $observation, 'nomenclature_type_status') . '';
  $html .= '            </select>';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Select nomenclature type status.') . '</div>';
  $html .= '        </div>';
  $html .= '      </div>';
  $html .= '    </fieldset>';
  $html .= '';
  $html .= '    <fieldset class=" collapsible"><legend>' .  t('Ecosystem/ Habitat Type') . '</legend>';
  $html .= '      <div class="form-item" id="edit-wo-parent-ecosystem-wrapper">';
  $html .= '        <div style="width:150px; float: left;">';
  $html .= '          <label for="edit-wo-parent-ecosystem" class="same-line">Ecosystem: </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/ecosystem?width=375" class="jTip" id="tooltip_ecosystem" name="Ecosystem:">?</a></span>';
  $html .= '        </div>';
  $html .= '        <div>';
  $html .= '          <select name="wo_parent_ecosystem" onchange="getChildEcosystems(parseInt(this.value))" class="form-select" id="edit-wo-parent-ecosystem" >';
  $html .= '            ' .  createDropdownOptions($parent_ecosystems_list, $observation, 'parent_ecosystem') . '';
  $html .= '          </select>';
  $html .= '        </div>';
  $html .= '        <div class="description">' .  t('Please select the main ecosystem.') . '</div>';
  $html .= '      </div>';
  $html .= '      ';
  $html .= '      <div class="form-item" id="edit-wo-child-ecosystem-wrapper" style="display:none">';
  $html .= '        <div style="width:150px; float: left;">';
  $html .= '          <label for="edit-wo-child-ecosystem" class="same-line">Sub Ecosystem: </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/eco_subsystem?width=375" class="jTip" id="tooltip_sub_ecosystem" name="Sub Ecosystem:">?</a></span>';
  $html .= '        </div>';
  $html .= '        <div>';
  $html .= '          <select name="wo_child_ecosystem" class="form-select" id="edit-wo-child-ecosystem" >';
  $html .= '          </select>';
  $html .= '        </div>';
  $html .= '        <div class="description">' .  t('Please select the sub-ecosystem.') . '</div>';
  $html .= '      </div>';
  $html .= '      ';
  $html .= '      <div class="form-item" id="edit-wo-nativeness-wrapper">';
  $html .= '        <div style="width:150px; float: left;">';
  $html .= '          <label for="edit-wo-nativeness" class="same-line">Nativeness: </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/nativeness?width=375" class="jTip" id="tooltip_nativeness" name="nativeness">?</a></span>';
  $html .= '        </div>';
  $html .= '        <div>';
  $html .= '          <select name="wo_nativeness" class="form-select" id="edit-wo-nativeness" >';
  $html .= '            ' .  createDropdownOptions($nativeness_list, $observation, 'nativeness') . '';
  $html .= '          </select>';
  $html .= '        </div>';
  $html .= '        <div class="description">' .  t('Please select the nativeness.') . '</div>';
  $html .= '      </div>';
  $html .= '      ';
  $html .= '      <div class="form-item" id="edit-wo-iucn-threat-category-wrapper">';
  $html .= '        <div style="width:150px; float: left;">';
  $html .= '          <label for="edit-wo-iucn-threat-category" class="same-line">IUCN Threat Category:';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/iucn_threat_category?width=375" class="jTip" id="tooltip_iucn_threat_category" name="IUCN Threat Category">?</a></span> </label>';
  $html .= '        </div>';
  $html .= '        <div>';
  $html .= '          <select name="wo_iucn_threat_category" class="form-select" id="edit-wo-iucn-threat-category" >';
  $html .= '            ' .  createDropdownOptions($iucn_threat_category_list, $observation, 'iucn_threat_category') . '';
  $html .= '          </select>';
  $html .= '        </div>';
  $html .= '        <div class="description">' .  t('Please select the IUCN threat category.') . '</div>';
  $html .= '      </div>';
  $html .= '      ';
  $html .= '    </fieldset>';
  $html .= '';
  // $html .= '    <div class="form-item" id="edit-wo-gender-wrapper">';
  // $html .= '      <label for="edit-wo-gender" class="same-line">' .  t('Gender') . ': </label>';
  // $html .= '      <select name="wo_gender" class="form-select" id="edit-wo-gender" >';
  // $html .= '        ' .  createDropdownOptions($gender_options, $observation, 'gender') . '';
  // $html .= '      </select>';
  // $html .= '      <div class="description">' .  t('Please select the gender of specimen.') . '</div>';
  // $html .= '    </div>';
  // $html .= '';
  // $html .= '    <div class="form-item" id="edit-wo-lifestage-wrapper">';
  // $html .= '      <label for="edit-wo-lifestage" class="same-line">' .  t('Life Stage') . ': </label>';
  // //$html .= '      <input type="text" maxlength="128" name="wo_lifestage" id="edit-wo-lifestage" size="10" value="" class="form-text" />';
  // $html .= '      <select name="wo_lifestage" class="form-select" id="edit-wo-lifestage" >';
  // $html .= '        ' .  createDropdownOptions($lifestage_list, $observation, 'lifestage') . '';
  // $html .= '      </select>';
  // $html .= '      <div class="description">' .  t('Enter the lifestage of the specimen observed.') . '</div>';
  // $html .= '    </div>';
  // $html .= '';
  $html .= '    <fieldset class=" collapsible">';
  $html .= '      <legend>' .  t('Temporal Information') . '</legend>';
  $html .= '      <fieldset class=" collapsible">';
  $html .= '        <legend>' .  t('Observation Date') . '</legend>';
  $html .= '        <div class="form-item" id="edit-wo-know-date-range-wrapper">';
  $html .= '          <label class="option" for="edit-wo-know-date-range">';
  $html .= '            <input type="checkbox" name="wo_know_date_range" id="edit-wo-know-date-range" value="1" onclick="toggleExactDate(this.checked)" class="form-checkbox" ' . ($observation->is_date_range ? 'checked' : '') . '/>';
  $html .= '            ' .  t('Enter observation date range.') . '';
  $html .= '          </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/date_range?width=375" class="jTip" id="tooltip_date_range" name="Date Range:">?</a></span>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-date-range-wrapper">';
  $html .= '          <div class="form-item" id="edit-wo-from-date-wrapper">';
  $html .= '            <div style="width:140px; float: left;">';
  $html .= '              <label for="edit-wo-from-date" class="same-line">' .  t('From Date') . ': <span class="form-required" title="This field is required.">*</span></label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/from_date?width=375" class="jTip" id="tooltip_from_date" name="From Date:">?</a></span>';
  $html .= '            </div>';
  $html .= '            <div>';
  $html .= '              <input type="text" maxlength="128" name="wo_from_date" id="edit-wo-from-date" size="11" value="' . get_text_observation_value($observation, 'from_date') . '" class="form-text datepicker" readonly="readonly" />';
  $html .= '            </div>';
  $html .= '            <div class="description">' .  t('Enter observation start date.') . '</div>';
  $html .= '          </div>';
  $html .= '';
  $html .= '          <div class="form-item" id="edit-wo-to-date-wrapper">';
  $html .= '            <div style="width:140px; float: left;">';
  $html .= '              <label for="edit-wo-to-date" class="same-line">' .  t('To Date') . ': <span class="form-required" title="This field is required.">*</span></label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/to_date?width=375" class="jTip" id="tooltip_to_date" name="To Date:">?</a></span>';
  $html .= '            </div>';
  $html .= '            <div>';
  $html .= '              <input type="text" maxlength="128" name="wo_to_date" id="edit-wo-to-date" size="11" value="' . get_text_observation_value($observation, 'to_date') . '" class="form-text datepicker" readonly="readonly" />';
  $html .= '            </div>';
  $html .= '            <div class="description">' .  t('Enter observation end date.') . '</div>';
  $html .= '          </div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-on-date-wrapper">';
  $html .= '          <div style="width:140px; float: left;">';
  $html .= '            <label for="edit-wo-on-date" class="same-line">' .  t('Observation Date') . ': <span class="form-required" title="This field is required.">*</span></label>';
  $html .= '          </div>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/on_date?width=375" class="jTip" id="tooltip_on_date" name="On Date:">?</a></span>';
  $html .= '          <div>';
  $html .= '            <input type="text" maxlength="128" name="wo_on_date" id="edit-wo-on-date" size="11" value="' . get_text_observation_value($observation, 'on_date') . '" class="form-text required datepicker" readonly="readonly" />';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter observation date.') . '</div>';
  $html .= '        </div>';
  $html .= '      </fieldset>';
  $html .= '';
  $html .= '      <fieldset class=" collapsible">';
  $html .= '        <legend>' .  t('Time') . '</legend>';
  $html .= '        <div class="form-item" id="edit-wo-know-exact-time-wrapper">';
  $html .= '          <label class="option" for="edit-wo-know-exact-time">';
  $html .= '            <input type="checkbox" name="wo_know_exact_time" id="edit-wo-know-exact-time" value="1" onclick="toggleExactTime(this.checked)" class="form-checkbox" ' . ($observation->is_exact_time ? 'checked' : '') . '/>';
  $html .= '            ' .  t('Know exact observation time.') . '';
  $html .= '          </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/know_exact_time?width=375" class="jTip" id="tooltip_know_exact_time" name="Know the exact_time:">?</a></span>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-exact-time-wrapper">';
  $html .= '          <div style="width:140px; float: left;">';
  $html .= '            <label for="edit-wo-exact-time" class="same-line">' .  t('Exact Observation Time') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/exact_time?width=375" class="jTip" id="tooltip_exact_time" name="Exact Time:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <div class="container-inline">';
  $html .= '              <div class="form-item" id="edit-wo-exact-time-hour-wrapper">';
  $html .= '                <select name="wo_exact_time[hour]" class="form-select" id="edit-wo-exact-time-hour" >';
  $html .= '                 ' .  createDropdownOptions(getHoursOptions(), $observation, 'hour') . '';
  //$html .= '                  <!--<option value="1">01</option><option value="2">02</option><option value="3">03</option><option value="4">04</option><option value="5" selected="selected">05</option><option value="6">06</option><option value="7">07</option><option value="8">08</option><option value="9">09</option><option value="10">10</option><option value="11">11</option><option value="12">12</option>-->';
  $html .= '                </select>';
  $html .= '              </div>';
  $html .= '';
  $html .= '              <div class="form-item" id="edit-wo-exact-time-minute-wrapper">';
  $html .= '                <select name="wo_exact_time[minute]" class="form-select" id="edit-wo-exact-time-minute" >';
  $html .= '                 ' .  createDropdownOptions(getMinutesOptions(), $observation, 'minute') . '';
  //$html .= '               <!--<option value="0">00</option><option value="1">01</option><option value="2">02</option><option value="3">03</option><option value="4">04</option><option value="5">05</option><option value="6">06</option><option value="7">07</option><option value="8">08</option><option value="9">09</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option><option value="32">32</option><option value="33">33</option><option value="34">34</option><option value="35">35</option><option value="36">36</option><option value="37">37</option><option value="38">38</option><option value="39" selected="selected">39</option><option value="40">40</option><option value="41">41</option><option value="42">42</option><option value="43">43</option><option value="44">44</option><option value="45">45</option><option value="46">46</option><option value="47">47</option><option value="48">48</option><option value="49">49</option><option value="50">50</option><option value="51">51</option><option value="52">52</option><option value="53">53</option><option value="54">54</option><option value="55">55</option><option value="56">56</option><option value="57">57</option><option value="58">58</option><option value="59">59</option>-->';
  $html .= '               </select>';
  $html .= '             </div>';
  $html .= '';
  $html .= '              <div class="form-item" id="edit-wo-exact-time-meridiem-wrapper">';
  $html .= '                <select name="wo_exact_time[meridiem]" class="form-select" id="edit-wo-exact-time-meridiem" >';
  $html .= '                  ' .  createDropdownOptions(array(t('am'), t('pm')), $observation, 'meridiem') . '';
  $html .= '                </select>';
  $html .= '              </div>';
  $html .= '            </div>';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter observation time.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-part-of-day-wrapper">';
  $html .= '          <div style="width:140px; float: left;">';
  $html .= '            <label for="edit-wo-part-of-day">' .  t('Part of Day') . ': ';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/part_of_day?width=375" class="jTip" id="tooltip_part_of_day" name="Which part of the day:">?</a></span> </label>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <select name="wo_part_of_day[]" multiple="multiple"  class="form-select" id="edit-wo-part-of-day"  size="5">';
  //$html .= '          <select name="wo_part_of_day[]" class="form-select" id="edit-wo-part-of-day">';
  $html .= '              ' .  createDropdownOptions($pod_options, $observation, 'pods') . '';
  $html .= '            </select>';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Please select the observation part of day. You can select multiple options by pressing Ctrl key.') . '</div>';
  $html .= '        </div>';
  $html .= '      </fieldset>';
  $html .= '    </fieldset>';
  $html .= '';
  $html .= '    <fieldset class=" collapsible">';
  $html .= '      <legend>' .  t('Positional Level Parameters') . '</legend>';
  $html .= '      <div class="form-item" id="edit-wo-altitude-wrapper">';
  $html .= '        <div style="width:150px; float: left;">';
  $html .= '          <label for="edit-wo-altitude" class="same-line">' .  t('Altitude') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/altitude?width=375" class="jTip" id="tooltip_altitude" name="Altitude:">?</a></span>';
  $html .= '        </div>';
  $html .= '        <div>';
  $html .= '          <input type="text" maxlength="20" name="wo_altitude" id="edit-wo-altitude" size="30" value="' . get_text_observation_value($observation, 'altitude') . '" class="form-text numeric" />';
  $html .= '        </div>';
  $html .= '        <div class="description">' .  t('Enter altitude in meters.') . '</div>';
  $html .= '      </div>';
  $html .= '';
  $html .= '      <div class="form-item" id="edit-wo-depth-wrapper">';
  $html .= '        <div style="width:150px; float: left;">';
  $html .= '          <label for="edit-wo-depth" class="same-line">' .  t('Depth') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/depth?width=375" class="jTip" id="tooltip_depth" name="Depth:">?</a></span>';
  $html .= '        </div>';
  $html .= '        <div>';
  $html .= '          <input type="text" maxlength="20" name="wo_depth" id="edit-wo-depth" size="30" value="' . get_text_observation_value($observation, 'depth') . '" class="form-text numeric" />';
  $html .= '        </div>';
  $html .= '        <div class="description">' .  t('Enter depth in meters.') . '</div>';
  $html .= '      </div>';
  $html .= '    </fieldset>';
  $html .= '    ';
  $html .= '    <fieldset class=" collapsible">';
  $html .= '      <legend>' .  t('Location Information') . '</legend>';
  $html .= '      <div class="form-item" id="edit-wo-country-wrapper">';
  $html .= '        <div style="width:150px; float: left;">';
  $html .= '          <label for="edit-wo-country" class="same-line">' .  t('Country') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/country?width=375" class="jTip" id="tooltip_country" name="Country:">?</a></span>';
  $html .= '        </div>';
  $html .= '        <div>';
  $html .= '          <select name="wo_country" onchange="getRegionsForCountry(parseInt(this.value))" class="form-select" id="edit-wo-country" >';
  $html .= '            ' .  createDropdownOptions($countries_list, $observation, 'country') . '';
  $html .= '          </select>';
  $html .= '        </div>';
  $html .= '        <div class="description">' .  t('Please select the country of observation.') . '</div>';
  $html .= '      </div>';
  $html .= '      ';
  $html .= '      <div class="form-item" id="edit-wo-region-wrapper">';
  $html .= '        <div style="width:150px; float: left;">';
  $html .= '          <label for="edit-wo-region" class="same-line">' .  t('Region/ State') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/region_state?width=375" class="jTip" id="tooltip_region_state" name="Region/State:">?</a></span>';
  $html .= '        </div>';
  $html .= '        <div>';
  $html .= '          <select name="wo_region" onchange="getCitiesForRegion(parseInt(this.value))" class="form-select" id="edit-wo-region" >';
  $html .= '          </select>';
  $html .= '        </div>';
  $html .= '        <div class="description">' .  t('Please select the region/ state of observation.') . '</div>';
  $html .= '      </div>';
  $html .= '      ';
  $html .= '      <div class="form-item" id="edit-wo-city-wrapper">';
  $html .= '        <div style="width:150px; float: left;">';
  $html .= '          <label for="edit-wo-city" class="same-line">' .  t('City') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/city?width=375" class="jTip" id="tooltip_city" name="City:">?</a></span>';
  $html .= '        </div>';
  $html .= '        <div>';
  $html .= '          <select name="wo_city" onchange="onCitySelect()" class="form-select" id="edit-wo-city" >';
  $html .= '          </select>';
  $html .= '        </div>';
  $html .= '        <div class="description">' .  t('Please select the city of observation.') . '</div>';
  $html .= '      </div>';
  $html .= '      ';
  $html .= '      <div class="form-item" id="edit-wo-locality-wrapper">';
  $html .= '        <div style="width:150px; float: left;">';
  $html .= '          <label for="edit-wo-locality" class="same-line">' .  t('Locality') . ': ';
  $html .= '            <span class="form-required" title="' .  t('This field is required.') . '">*</span>';
  $html .= '          </label>';
  $html .= '          <span class="formInfo"><a href="'.$base_path.'observation/tooltip/locality?width=375" class="jTip" id="tooltip_locality" name="Locality:">?</a></span>';
  $html .= '        </div>';
  $html .= '        <div>';
  $html .= '          <input type="text" maxlength="50" name="wo_locality" id="edit-wo-locality" size="30" value="' . get_text_observation_value($observation, 'locality') . '" class="form-text" />';
  $html .= '        </div>';
  $html .= '        <div class="description">' .  t('Enter the locality.') . '</div>';
  $html .= '      </div>';

  $pointtitle = t('Point');
  $pointmsg1 = t('Please enter the latitude and longitude values.');
  $pointmsg2 = t('You could also mark a point directly on the map.
    Please select the point tool in the map toolbar, and click on
    the map to mark a point.');

  $bboxtitle = t('Bounding Box');
  $bboxmsg1 = t('Please enter the top-left and bottom-right latitude and longitude values.');
  $bboxmsg2 = t('You could also mark the bouding box directly on the
    map. Please select the bounding box tool in the map toolbar, and
    click on the map and drag the mouse to draw the bouding box.');

  $polytitle = t('Polygon');
  $polymsg = t('Select the polygon tool from the map toolbar. Click on map to add a point. Double click to stop drawing a polygon.');

  $lattext = t('lat');
  $lontext = t('lon');
  $toptext = t('top');
  $bottomtext = t('bottom');
  $lefttext = t('left');
  $righttext = t('right');
  $marktext = t('Mark');
  $zoomtext = t('Zoom');

  $html .= <<<EOT
    <DIV id="tabsMapportal_1">
      <UL>
        <LI><A href="#tabs-1_1">{$pointtitle}</A></LI>
        <LI><A href="#tabs-2_1">{$bboxtitle}</A></LI>
        <LI><A href="#tabs-3_1">{$polytitle}</A></LI>
      </UL>
      <DIV id="tabs-1_1">
        {$pointmsg1}
        <div>
          {$lattext}: <input type="textbox" id="txtMPPtLat_1" size="20"></input> {$lontext}: <input type="textbox" id="txtMPPtLon_1" size="20"><br>
          </input><input type="button" id="btnMPPt_1" value="{$marktext}"></input>
        </div>
        {$pointmsg2}
      </DIV>
      <DIV id="tabs-2_1">
        {$bboxmsg1}
        <div>
          {$toptext}-{$lefttext} {$lattext}: <input type="textbox" id="txtMPBBoxTLLat_1" size="20"></input> {$lontext}: <input type="textbox" id="txtMPBBoxTLLon_1" size="20"></input><br>
          {$bottomtext}-{$righttext} {$lattext}: <input type="textbox" id="txtMPBBoxBRLat_1" size="20"></input> {$lontext}: <input type="textbox" id="txtMPBBoxBRLon_1" size="20"></input><br>
          <input type="button" id="btnMPBBox_1" value="{$marktext}"></input>
        </div>
        {$bboxmsg2}
      </DIV>
      <DIV id="tabs-3_1">
        {$polymsg}
      </DIV>
    </DIV>
EOT;
  $html .= '    </fieldset>';
  $html .= '';
  $html .= '    <fieldset class=" collapsible">';
  $html .= '      <legend>' .  t('Waterbody Information') . '</legend>';
  $html .= '      <div class="form-item" id="edit-wo-haswaterbody-wrapper">';
  $html .= '        <label class="option" for="edit-wo-haswaterbody" class="same-line">';
  $html .= '          <input type="checkbox" name="wo_haswaterbody" id="edit-wo-haswaterbody" value="1" onclick="toggleWaterbodyInfo(this.checked)" class="form-checkbox" ' . ($observation->is_waterbody_related ? 'checked' : '') . '/>';
  $html .= '          ' .  t('Is any waterbody related to the observation.') . '';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/waterbody_observation?width=375" class="jTip" id="tooltip_waterbody_observation" name="Waterbody Observation:">?</a></span>';
  $html .= '        </label>';
  $html .= '      </div>';
  $html .= '      <div class="form-item" id="edit-wo-waterbody-type-wrapper">';
  $html .= '        <div style="width:150px; float: left;">';
  $html .= '          <label for="edit-wo-waterbody-type" class="same-line">' .  t('Waterbody Type') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/waterbody_type?width=375" class="jTip" id="tooltip_waterbody_type" name="Type of waterbody:">?</a></span>';
  $html .= '        </div>';
  $html .= '        <div>';
  $html .= '          <select name="wo_waterbody_type" class="form-select" id="edit-wo-waterbody-type" >';
  $html .= '            ' .  createDropdownOptions($waterbody_type_list, $observation, 'waterbody_type') . '';
  $html .= '          </select>';
  $html .= '        </div>';
  $html .= '        <div class="description">' .  t('Please select the waterbody type.') . '</div>';
  $html .= '      </div>';
  $html .= '      <div class="form-item" id="edit-wo-waterbody-name-wrapper">';
  $html .= '        <div style="width:150px; float: left;">';
  $html .= '          <label for="edit-wo-waterbody-name" class="same-line">';
  $html .= '            ' . t('Waterbody Name') . ': ';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/waterbody_name?width=375" class="jTip" id="tooltip_waterbody_name" name="Name of the waterbody:">?</a></span>';
  $html .= '            <span class="form-required" title="' .  t('This field is required.') . '">*</span>';
  $html .= '          </label>';
  $html .= '        </div>';
  $html .= '        <div>';
  $html .= '          <input type="text" maxlength="50" name="wo_waterbody_name" id="edit-wo-waterbody-name" size="30" value="' . get_text_observation_value($observation, 'waterbody_name') . '" class="form-text" />';
  $html .= '        </div>';
  $html .= '        <div class="description">' .  t('Enter the waterbody name.') . '</div>';
  $html .= '      </div>';
  $html .= '    </fieldset>';
  $html .= '';
  $html .= '    <div class="form-item" id="edit-wo-num-individuals-wrapper">';
  $html .= '      <div style="width:160px; float: left;">';
  $html .= '        <label for="edit-wo-num-individuals" class="same-line">' .  t('Number of Individuals') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/number_individuals?width=375" class="jTip" id="tooltip_number_individuals" name="Number of individuals Observed:">?</a></span>';
  $html .= '      </div>';
  $html .= '      <div>';
  $html .= '        <input type="text" maxlength="128" name="wo_num_individuals" id="edit-wo-num-individuals" size="10" value="' . get_text_observation_value($observation, 'num_individuals') . '" class="form-text integer" />';
  $html .= '      </div>';
  $html .= '      <div class="description">' .  t('Enter number of individuals observed.') . '</div>';
  $html .= '    </div>';
  $html .= '';
  $html .= '    <div class="form-item" id="edit-wo-basis-of-record-wrapper">';
  $html .= '      <div style="width:160px; float: left;">';
  $html .= '        <label for="edit-wo-basis-of-record" class="same-line">' .  t('Basis of Record') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/basis_of_record?width=375" class="jTip" id="tooltip_basis_of_record" name="Basis of record:">?</a></span>';
  $html .= '      </div>';
  $html .= '      <div>';
  $html .= '        <select name="wo_basis_of_record" class="form-select" id="edit-wo-basis-of-record" >';
  $html .= '          ' .  createDropdownOptions($basis_of_record_list, $observation, 'basis_of_record') . '';
  $html .= '        </select>';
  $html .= '      </div>';
  $html .= '      <div class="description">' .  t('Enter the basis of record.') . '</div>';
  $html .= '    </div>';
  $html .= '';
  $html .= '    <div class="form-item" id="edit-wo-record-language-wrapper">';
  $html .= '      <div style="width:160px; float: left;">';
  $html .= '        <label for="edit-wo-record-language" class="same-line">' .  t('Language of Record') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/language_of_record?width=375" class="jTip" id="tooltip_language_of_record" name="Language of record:">?</a></span>';
  $html .= '      </div>';
  $html .= '      <div>';
  //$html .= '      <input type="text" maxlength="128" name="wo_record_language" id="edit-wo-record-language" size="10" value="' . get_text_observation_value($observation, 'record_language') . '" class="form-text" />';
  $html .= '        <input type="text" maxlength="128" name="wo_record_language" id="edit-wo-record-language" size="10" value="' . get_text_observation_value($observation, 'record_language') . '" class="form-text" disabled/>';
  $html .= '      </div>';
  $html .= '      <div class="description">' .  t('Enter the language in which the observation will be recorded.') . '</div>';
  $html .= '    </div>';
  $html .= '';

  $observer_type = 'self';
  if ($observation != NULL) {
    global $user;
    if (($observation->created_by == $user->uid) && (get_text_observation_value($observation, 'observer_email') == $user->mail)) {
      $observer_type = 'self';
    }
    else {
      $observer_type = 'other';
    }
  }

  $html .= '    <fieldset class=" collapsible">';
  $html .= '      <legend>' .  t('Observer Information') . '</legend>';
  $html .= '      <div class="form-item">';
  $html .= '        <label>' .  t('Observer') . ': ';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/observer?width=375" class="jTip" id="tooltip_observer" name="Observer:">?</a></span> </label>';
  $html .= '        <div class="form-radios"><div class="form-item" id="edit-wo-radio-observer-0-wrapper">';
  $html .= '          <label class="option" for="edit-wo-radio-observer-0">';
  $html .= '            <input type="radio" id="edit-wo-radio-observer-0" name="wo_radio_observer" value="0" '.($observer_type == 'self' ? 'checked' : '').' onclick="toggleOtherObserverDetails(parseInt(this.value))" class="form-radio" />';
  $html .= '            ' .  t('Self') . '';
  $html .= '          </label>';

  $html .= '          </div>';
  $html .= '          <div class="form-item" id="edit-wo-radio-observer-1-wrapper">';
  $html .= '            <label class="option" for="edit-wo-radio-observer-1">';
  $html .= '              <input type="radio" id="edit-wo-radio-observer-1" name="wo_radio_observer" value="1" '.($observer_type == 'other' ? 'checked' : '').' onclick="toggleOtherObserverDetails(parseInt(this.value))" class="form-radio" />';
  $html .= '              ' .  t('Other') . '';
  $html .= '            </label>';
  $html .= '          </div>';
  $html .= '        </div>';
  $html .= '      </div>';
  $html .= '      ';
  //$readonly = ($observation != NULL ? 'readonly' : '');
  $html .= '      <fieldset id="fieldset_other_observer" class=" collapsible">';
  $html .= '        <legend>' .  t('Other Observers') . '</legend>';
  $html .= '        <div class="form-item" id="edit-wo-select-other-observer-wrapper">';
  $html .= '          <div style="width:150px; float: left;">';
  $html .= '            <label for="edit-wo-select-other-observer" class="same-line">' .  t('Observer') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/other_observer?width=375" class="jTip" id="tooltip_other_observer" name="Other observer:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <select name="wo_select_other_observer" onchange="getOtherObserverDetails(parseInt(this.value))" class="form-select" id="edit-wo-select-other-observer" >';
  $html .= '            ' .  createDropdownOptions($observers_list, $observation, 'observer') . '';
  $html .= '            </select>';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Please select an observer. To enter new observer details, select new.') . '</div>';
  $html .= '        </div>';
  $html .= '        ';
  $html .= '        <div class="form-item" id="edit-wo-other-observer-first-name-wrapper">';
  $html .= '          <div style="width:150px; float: left;">';
  $html .= '            <label for="edit-wo-other-observer-first-name" class="same-line">' .  t('First Name') . ': <span class="form-required" title="This field is required.">*</span></label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/observer_first_name?width=375" class="jTip" id="tooltip_observer_first_name" name="First name of the observer:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" maxlength="50" name="wo_other_observer_first_name" id="edit-wo-other-observer-first-name" size="30" value="' . get_text_observation_value($observation, 'observer_fname') . '" class="form-text required" />';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter the first name.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-other-observer-last-name-wrapper">';
  $html .= '          <div style="width:150px; float: left;">';
  $html .= '            <label for="edit-wo-other-observer-last-name" class="same-line">' .  t('Last Name') . ': <span class="form-required" title="This field is required.">*</span></label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/observer_last_name?width=375" class="jTip" id="tooltip_observer_last_name" name="Last name of the observer:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" maxlength="50" name="wo_other_observer_last_name" id="edit-wo-other-observer-last-name" size="30" value="' . get_text_observation_value($observation, 'observer_lname') . '" class="form-text required" />';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter the last name.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-other-observer-email-id-wrapper">';
  $html .= '          <div style="width:150px; float: left;">';
  $html .= '            <label for="edit-wo-other-observer-email-id" class="same-line">' .  t('Email ID') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/observer_email?width=375" class="jTip" id="tooltip_observer_email" name="Email id of the observer:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" maxlength="50" name="wo_other_observer_email_id" id="edit-wo-other-observer-email-id" size="30" value="' . get_text_observation_value($observation, 'observer_email') . '" class="form-text" />';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter the email ID.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-other-observer-affiliation-wrapper">';
  $html .= '          <div style="width:150px; float: left;">';
  $html .= '            <label for="edit-wo-other-observer-affiliation" class="same-line">' .  t('Affiliation') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/affiliation?width=375" class="jTip" id="tooltip_affiliation" name="Affiliation:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" maxlength="50" name="wo_other_observer_affiliation" id="edit-wo-other-observer-affiliation" size="30" value="' . get_text_observation_value($observation, 'observer_affiliation') . '" class="form-text" />';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter the affiliation.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-other-observer-address1-wrapper">';
  $html .= '          <div style="width:150px; float: left;">';
  $html .= '            <label for="edit-wo-other-observer-address1" class="same-line">' .  t('Address Line 1') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/observer_address1?width=375" class="jTip" id="tooltip_observer_address1" name="Address Line 1:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" maxlength="50" name="wo_other_observer_address1" id="edit-wo-other-observer-address1" size="30" value="' . get_text_observation_value($observation, 'observer_address1') . '" class="form-text" />';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Address Line 1.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-other-observer-address2-wrapper">';
  $html .= '          <div style="width:150px; float: left;">';
  $html .= '            <label for="edit-wo-other-observer-address2" class="same-line">' .  t('Address Line 2') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/observer_address2?width=375" class="jTip" id="tooltip_observer_address2" name="Address Line 2:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" maxlength="50" name="wo_other_observer_address2" id="edit-wo-other-observer-address2" size="30" value="' . get_text_observation_value($observation, 'observer_address2') . '" class="form-text" />';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Address Line 2.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-other-observer-city-wrapper">';
  $html .= '          <div style="width:150px; float: left;">';
  $html .= '            <label for="edit-wo-other-observer-city" class="same-line">' .  t('City') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/observer_city?width=375" class="jTip" id="tooltip_observer_city" name="City:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" maxlength="50" name="wo_other_observer_city" id="edit-wo-other-observer-city" size="30" value="' . get_text_observation_value($observation, 'observer_city') . '" class="form-text" />';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter the city.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-other-observer-region-wrapper">';
  $html .= '          <div style="width:150px; float: left;">';
  $html .= '            <label for="edit-wo-other-observer-region" class="same-line">' .  t('Region/ State') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/observer_region?width=375" class="jTip" id="tooltip_observer_region" name="region:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" maxlength="50" name="wo_other_observer_region" id="edit-wo-other-observer-region" size="30" value="' . get_text_observation_value($observation, 'observer_region') . '" class="form-text" />';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter the region.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-other-observer-country-wrapper">';
  $html .= '          <div style="width:150px; float: left;">';
  $html .= '            <label for="edit-wo-other-observer-country" class="same-line">' .  t('Country') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/observer_country?width=375" class="jTip" id="tooltip_observer_country" name="country:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" maxlength="50" name="wo_other_observer_country" id="edit-wo-other-observer-country" size="30" value="' . get_text_observation_value($observation, 'observer_country') . '" class="form-text" />';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter the country.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-other-observer-phone-number-wrapper">';
  $html .= '          <div style="width:150px; float: left;">';
  $html .= '            <label for="edit-wo-other-observer-phone-number" class="same-line">' .  t('Phone number') . ': </label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/phone_number?width=375" class="jTip" id="tooltip_phone_number" name="Phone Number:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" maxlength="20" name="wo_other_observer_phone_number" id="edit-wo-other-observer-phone-number" size="30" value="' . get_text_observation_value($observation, 'observer_phoneno') . '" class="form-text" />';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter the phone number.') . '</div>';
  $html .= '        </div>';
  $html .= '';
  $html .= '        <div class="form-item" id="edit-wo-other-observer-mobile-wrapper">';
  $html .= '          <div style="width:150px; float: left;">';
  $html .= '            <label for="edit-wo-other-observer-mobile" class="same-line">' .  t('Mobile Number') . ': <span class="form-required" title="This field is required.">*</span></label>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/mobile_number?width=375" class="jTip" id="tooltip_mobile_number" name="Mobile Number:">?</a></span>';
  $html .= '          </div>';
  $html .= '          <div>';
  $html .= '            <input type="text" maxlength="20" name="wo_other_observer_mobile" id="edit-wo-other-observer-mobile" size="30" value="' . get_text_observation_value($observation, 'observer_mobile') . '" class="form-text required" />';
  $html .= '          </div>';
  $html .= '          <div class="description">' .  t('Enter the mobile number.') . '</div>';
  $html .= '        </div>';
  $html .= '      </fieldset>';
  $html .= '    </fieldset>';
  $html .= '';
  $html .= '    <div class="form-item" id="edit-wo-comments-wrapper">';
  $html .= '      <label for="edit-wo-comments">' .  t('Comments') . ': ';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/comments?width=375" class="jTip" id="tooltip_comments" name="Comments:">?</a></span> </label>';
  $html .= '      <textarea cols="60" rows="5" name="wo_comments" id="edit-wo-comments" class="form-textarea resizable">' . get_text_observation_value($observation, 'comments') . '</textarea>';
  $html .= '      <div class="description">' .  t('Enter comments.') . '</div>';
  $html .= '    </div>';
  $html .= '    ';
  if ($observation == NULL) {
    $html .= '    <fieldset id="wo-fs-image">';
    $html .= '      <legend>Image</legend>';
    $html .= '      <div class="form-item" >';
    $html .= '        <div style="width:150px; float: left;">';
    $html .= '          <label for="wo-imgfile">Upload Image: <span class="form-required" title="This field is required.">*</span>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/image?width=375" class="jTip" id="tooltip_image" name="Image:">?</a></span></label>';
    $html .= '        </div>';
    $html .= '        <div>';
    $html .= '          <input type="file" name="wo_imgfile" id="wo-imgfile" />';
    $html .= '        </div>';
    $html .= '      </div>';
    $html .= '      <div class="form-item" id="edit-wo-image-copyright-wrapper">';
    $html .= '        <div style="width:150px; float: left;">';
    $html .= '          <label for="edit-wo-image-copyright" class="same-line">' .  t('Copyright information') . ':';
    $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/copyright?width=375" class="jTip" id="tooltip_copyright" name="Copyright:">?</a></span></label>';
    $html .= '        </div>';
    $html .= '        <div>';
    $html .= '          <input type="text" maxlength="20" name="wo_image_copyright" id="edit-wo-image-copyright" size="30" value="" class="form-text required" />';
    $html .= '        </div>';
    $html .= '        <div class="description">' .  t('Please enter the copyright information for the image.') . '</div>';
    $html .= '      </div>';
    $html .= '    </fieldset>';
  }

  if ($isValidate != NULL && $isValidate == TRUE) {
    $validation = $observation->validation;
    $pend_sel = '';
    $appr_sel = '';
    $rej_sel = '';
    $val_comments = '';
    $len = count($validation);
    if ($len > 0) {
      global $user;
      $uid = $user->uid;
      for ($i = 0; $i < $len; $i++) {
        $val_info = $validation[$i];
        if ($uid == $val_info['validated_by_id']) {
          switch ($val_info['status']) {
            case 'Pending':
              $pend_sel = 'selected';
              break;
            case 'Approved':
              $appr_sel = 'selected';
              break;
            case 'Rejected':
              $rej_sel = 'selected';
              break;
          }

          $val_comments = $val_info['comments'];
        }
      }
    }
    $html .= '    <fieldset>';
    $html .= '      <legend>Validation</legend>';
    $html .= '      <div class="form-item">';
    $html .= '        Status:';
    $html .= '        <select name="validation_status" id="edit-wo-select-validation-status">';
    $html .= '          <option value="0" '.$pend_sel.'>Pending</option>';
    $html .= '          <option value="1" '.$appr_sel.'>Approved</option>';
    $html .= '          <option value="2" '.$rej_sel.'>Rejected</option>';
    $html .= '        </select>';
    $html .= '      </div>';
    $html .= '      <div class="form-item">';
    $html .= '        Comments:';
    $html .= '            <span class="form-required" title="' .  t('This field is required.') . '">*</span>';
    $html .= '        <textarea name="validation_comments" id="edit-wo-validation-comments" cols="100" rows="5">'.$val_comments.'</textarea>';
    $html .= '      </div>';
    $html .= '    </fieldset>';
  }
  $html .= '    <fieldset>';
  $html .= '      <legend>Captcha</legend>';
  $html .= '      <div class="form-item">';
  $html .= '        <div>';
  $html .= '          <img id="wo_captcha" src=\''.base_path().'observation/data/{"action":"getCaptchaImage"}\'></img>';
  $html .= '          <input type="button" id="wo_reload_captcha" value="Reload" class="form-submit" onclick="reloadCaptcha(\'wo_captcha\')"/>';
  $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/captcha?width=375" class="jTip" id="tooltip_captcha" name="Captcha:">?</a></span>';
  $html .= '        </div>';
  $html .= '        <input type="text" maxlength="5" name="wo_captcha" id="edit-wo-captcha" size="10" value="" class="form-text required" />';
  $html .= '        <span class="form-required" title="' .  t('This field is required.') . '">*</span>';
  $html .= '        <div class="description">' .  t('Enter the characters that you see above.') . '</div>';
  $html .= '      </div>';
  $html .= '    </fieldset>';
  $html .= '    <input type="button" name="op" id="edit-wo-submit" value="Submit" class="form-submit" onclick="submitObservation()"/>';

  $html .= '  </div>';
  $html .= '';
  $html .= '  <input type="hidden" name="wo_observation_id" id="edit-wo-observation_id" value="' . $observation_id . '"  />';
  $html .= '  <input type="hidden" name="wo_topology" id="edit-wo-topology" value=""  />';
  if ($isValidate != NULL && $isValidate == TRUE) {
    $html .= '  <input type="hidden" name="wo_is_validate" value="1"  />';
  }
  $html .= '';
  $html .= '</form>';
  $html .= '<form id="frm-image-upload" action="'.base_path().'observation/data" id="uploadimageform" enctype="multipart/form-data" method="post" style="display:none">';
  $html .= '</form>';

  $html .= get_map_html();
  if ($observation != NULL) {
    if ($isValidate != NULL && $isValidate == TRUE) {
      $html .= get_preview_images_html($observation->id);
    }
  }

  return $html;
}

function get_map_html() {
  $pointtitle = t('Point');
  $pointmsg1 = t('Please enter the latitude and longitude values.');
  $pointmsg2 = t('You could also mark a point directly on the map.
    Please select the point tool in the map toolbar, and click on
    the map to mark a point.');

  $bboxtitle = t('Bounding Box');
  $bboxmsg1 = t('Please enter the top-left and bottom-right latitude and longitude values.');
  $bboxmsg2 = t('You could also mark the bouding box directly on the
    map. Please select the bounding box tool in the map toolbar, and
    click on the map and drag the mouse to draw the bouding box.');

  $polytitle = t('Polygon');
  $polymsg = t('Select the polygon tool from the map toolbar. Click on map to add a point. Double click to stop drawing a polygon.');

  $lattext = t('lat');
  $lontext = t('lon');
  $toptext = t('top');
  $bottomtext = t('bottom');
  $lefttext = t('left');
  $righttext = t('right');
  $marktext = t('Mark');
  $zoomtext = t('Zoom');

  $html = <<<EOT
  <div id="mapArea">
    <DIV id="tabsMapportal" style="display:none;">
      <UL>
        <LI><A href="#tabs-1">{$pointtitle}</A></LI>
        <LI><A href="#tabs-2">{$bboxtitle}</A></LI>
        <LI><A href="#tabs-3">{$polytitle}</A></LI>
      </UL>
      <DIV id=tabs-1>
        {$pointmsg1}
        <div>
          {$lattext}: <input type="textbox" id="txtMPPtLat" size="20"></input> {$lontext}: <input type="textbox" id="txtMPPtLon" size="20"><br>
          </input><input type="button" id="btnMPPt" value="{$marktext}"></input>
        </div>
        {$pointmsg2}
        <div class="close-map-tabs">
          <a href="#" class="ui-dialog-titlebar-close ui-corner-all" role="button" unselectable="on" style="-moz-user-select: none;">
            <span class="ui-icon ui-icon-closethick" unselectable="on" style="-moz-user-select: none;">close</span>
          </a>
        </div>
      </DIV>
      <DIV id=tabs-2>
        {$bboxmsg1}
        <div>
          {$toptext}-{$lefttext} {$lattext}: <input type="textbox" id="txtMPBBoxTLLat" size="20"></input> {$lontext}: <input type="textbox" id="txtMPBBoxTLLon" size="20"></input><br>
          {$bottomtext}-{$righttext} {$lattext}: <input type="textbox" id="txtMPBBoxBRLat" size="20"></input> {$lontext}: <input type="textbox" id="txtMPBBoxBRLon" size="20"></input><br>
          <input type="button" id="btnMPBBox" value="{$marktext}"></input>
        </div>
        {$bboxmsg2}
        <div class="close-map-tabs">
          <a href="#" class="ui-dialog-titlebar-close ui-corner-all" role="button" unselectable="on">
            <span class="ui-icon ui-icon-closethick" unselectable="on" style="-moz-user-select: none;">close</span>
          </a>
        </div>
      </DIV>
      <DIV id=tabs-3>
        {$polymsg}
        <div class="close-map-tabs">
          <a href="#" class="ui-dialog-titlebar-close ui-corner-all" role="button" unselectable="on">
            <span class="ui-icon ui-icon-closethick" unselectable="on" style="-moz-user-select: none;">close</span>
          </a>
        </div>
      </DIV>
    </DIV>
    <div id="divMPAddress">
      <input type="text" id="txtMPAddress"></input><input type="button" id="btnMPGotoAddr" value="{$zoomtext}"></input>
    </div>
    <!-- map -->
    <div id="map" style="height: 100%; width: 100%;">

    </div>
    <!-- map ends -->
  </div>
  <!-- mapArea ends -->
EOT;

  return $html;
}

function createDropdownOptions($arr, $observation, $type = '') {
  $options = '';
  if (count($arr) > 0) {
    if ($observation == NULL) {
      switch($type) {
        case 'country':
          foreach ($arr as $id => $name) {
            if ($name == 'World') {
              $options .= '<option title="'.t($name).'" value="'.$id.'" selected="selected">'.t($name).'</option>';
            }
            else {
              $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
            }
          }
          break;
        case 'parent_ecosystem':
          foreach ($arr as $id => $name) {
            if ($name == 'Unknown') {
              $options .= '<option title="'.t($name).'" value="'.$id.'" selected="selected">'.t($name).'</option>';
            }
            else {
              $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
            }
          }
          break;
        default:
          foreach ($arr as $id => $name) {
            $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
          }
          break;
      }
    }
    else {
      switch ($type) {
        case 'pods':
          $pods = $observation->pods;
          if (is_array($pods )) {
            foreach ($arr as $id => $name) {
              if (in_array($name, $pods)) {
                $options .= '<option title="'.t($name).'" value="'.$id.'" selected="selected">'.t($name).'</option>';
              }
              else {
                $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
              }
            }
          }
          else {
            foreach ($arr as $id => $name) {
              $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
            }
          }
          break;
        //case 'gender':
        //case 'lifestage':
        case 'waterbody_type':
        case 'basis_of_record':
        case 'taxanomic_status':
        case 'nomenclature_type_status':
        case 'nativeness':
        case 'iucn_threat_category':
          foreach ($arr as $id => $name) {
            if ($name == $observation->{$type}) {
              $options .= '<option title="'.t($name).'" value="'.$id.'" selected="selected">'.t($name).'</option>';
            }
            else {
              $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
            }
          }
          break;
        case 'country':
          foreach ($arr as $id => $name) {
            if ($name == $observation->location[$type]) {
              $options .= '<option title="'.t($name).'" value="'.$id.'" selected="selected">'.t($name).'</option>';
            }
            else {
              $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
            }
          }
          break;
        case 'hour':
          if (!empty($observation->at_time)) {
            $tm = explode(' ', $observation->at_time);
            $tm1 = explode(':', $tm[0]);
            $hr = $tm1[0];
            foreach ($arr as $id => $name) {
              if ($name == $tm1[0]) {
                $options .= '<option title="'.t($name).'" value="'.$id.'" selected="selected">'.t($name).'</option>';
              }
              else {
                $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
              }
            }
          }
          else {
            foreach ($arr as $id => $name) {
              $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
            }
          }
          break;
        case 'minute':
          if (!empty($observation->at_time)) {
            $tm = explode(' ', $observation->at_time);
            $tm1 = explode(':', $tm[0]);
            $min = $tm1[1];
            foreach ($arr as $id => $name) {
              if ($name == $min) {
                $options .= '<option title="'.t($name).'" value="'.$id.'" selected="selected">'.t($name).'</option>';
              }
              else {
                $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
              }
            }
          }
          else {
            foreach ($arr as $id => $name) {
              $options .= '<option value="'.$id.'">'.t($name).'</option>';
            }
          }
          break;
        case 'meridiem':
          if (!empty($observation->at_time)) {
            $tm = explode(' ', $observation->at_time);
            foreach ($arr as $id => $name) {
              if ($name == $tm[1]) {
                $options .= '<option title="'.t($name).'" value="'.$id.'" selected="selected">'.t($name).'</option>';
              }
              else {
                $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
              }
            }
          }
          else {
            foreach ($arr as $id => $name) {
              $options .= '<option value="'.$id.'">'.t($name).'</option>';
            }
          }
          break;
        case 'observer':
          foreach ($arr as $id => $name) {
            if ($id == $observation->observer['id']) {
              $options .= '<option title="'.t($name).'" value="'.$id.'" selected="selected">'.t($name).'</option>';
            }
            else {
              $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
            }
          }
          break;
        case 'parent_ecosystem':
          $query = 'select COALESCE(parent_id, id) as id from win_ecosystems where id = %d';
          $query_args = array($observation->ecosystem_id);
          $result = db_query($query, $query_args);
          if (!$result) {
            foreach ($arr as $id => $name) {
              $options .= '<option value="'.$id.'">'.t($name).'</option>';
            }
          }
          else {
            if ($obj = db_fetch_object($result)) {
              $eco_id = $obj->id;
              if ($eco_id != $observation->ecosystem_id) {
                drupal_add_js('var ddEcosystemDefaultValue = ' . $observation->ecosystem_id . '; ', 'inline');
              }
              foreach ($arr as $id => $name) {
                if ($id == $eco_id) {
                  $options .= '<option title="'.t($name).'" value="'.$id.'" selected="selected">'.t($name).'</option>';
                }
                else {
                  $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
                }
              }
            }
            else {
              foreach ($arr as $id => $name) {
                $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
              }
            }
          }
          break;
        case 'cn_language':
        case 'gender':
        case 'lifestage':
          $cninfo = $observation->common_names[0];
          foreach ($arr as $id => $name) {
            if ($name == $cninfo[$type]) {
              $options .= '<option title="'.t($name).'" value="'.$id.'" selected="selected">'.t($name).'</option>';
            }
            else {
              $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
            }
          }
          break;
        default:
          foreach ($arr as $id => $name) {
            $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
          }
          break;
      }
    }
  }
  return $options;
}

function getHoursOptions() {
  $options = drupal_map_assoc(range(1, 12));
  foreach ($options as $option) {
    $options[$option] = str_pad($options[$option], 2, '0', STR_PAD_LEFT);
  }

  return $options;
}

function getMinutesOptions() {
  $options = drupal_map_assoc(range(0, 59));
  foreach ($options as $option) {
    $options[$option] = str_pad($options[$option], 2, '0', STR_PAD_LEFT);
  }

  return $options;
}

function get_text_observation_value($observation, $type) {
  $val = '';

  if ($observation !== NULL) {
    switch ($type) {
      case 's_kingdom':
      case 's_phylum':
      case 's_class':
      case 's_order':
      case 's_family':
      case 's_genus':
      case 's_species':
      case 'num_individuals':
      case 'altitude':
      case 'depth':
      case 'waterbody_name':
      case 'from_date':
      case 'to_date':
      case 'on_date':
      case 'comments':
        $val = $observation->{$type};
        break;
      case 'record_language':
        $val = $observation->{$type};
        if (empty($val)) {
          $val = 'English';
        }
        break;
      case 'locality':
        $val = $observation->location[$type];
        break;
      case 'common_name':
        $common_names = $observation->common_names;
        if (count($common_names) > 0) {
          $val = $common_names[0]['common_name'];
        }
        break;
      case 'common_name_language':
        $common_names = $observation->common_names;
        if (count($common_names) > 0) {
          $val = $common_names[0]['cn_language'];
        }
        break;
      case 'common_name_region':
        $common_names = $observation->common_names;
        if (count($common_names) > 0) {
          $val = $common_names[0]['region'];
        }
        break;
      case 'common_name_english':
        $common_names = $observation->common_names;
        if (count($common_names) > 0) {
          $val = $common_names[0]['common_name_english'];
        }
        break;
      case 'observer_fname':
      case 'observer_lname':
      case 'observer_affiliation':
      case 'observer_email':
      case 'observer_address':
      case 'observer_phoneno':
      case 'observer_mobile':
        $arr = explode('_', $type);
        $val = $observation->observer[$arr[1]];
        break;
      case 'scientific_name':
        $scientific_name_info = $observation->scientific_name_info;
        $val = $scientific_name_info['s_name'];
        break;
      case 'scientific_name_author':
        $scientific_name_info = $observation->scientific_name_info;
        $val = $scientific_name_info['s_author'];
        break;
      case 'scientific_name_year':
        $scientific_name_info = $observation->scientific_name_info;
        $val = $scientific_name_info['s_year'];
        if ((int)$val == 0) {
          $val = '';
        }
        break;
      /*
      case 'from_date':
      case 'to_date':
      case 'on_date':
        $val = date('M d, Y', strtotime($observation->{$type})); // M d, Y
        break;
      */
    }
  }
  else {
    switch ($type) {
      case 'record_language':
        $val = 'English';
        break;
    }
  }

  return $val;
}

function show_more_common_names($common_names, $cn_languages, $gender_options, $lifestage_list) {
  $html = '';
  $cnt = count($common_names);
  for ($i = 1; $i < $cnt; $i++) { // Start with 1 since 0 has already been taken care of.
    $cn_info = $common_names[$i];
    $cn = $cn_info['common_name'];
    $cnl = $cn_info['cn_language'];
    $show_spell = 'style="display: block;"';
    if (strtolower($cnl) == 'english') {
      $show_spell = 'style="display: none;"';
    }
    $cnr = $cn_info['region'];
    $cne = $cn_info['common_name_english'];

    $html .= '      <fieldset class=" collapsible">';
    $html .= '        <legend>' .  t('Common Name ' . $i) . '</legend>';
    $html .= '          <a unselectable="on" role="button" class="removeCommonNameUI" href="#">';
    $html .= '            <span style="-moz-user-select: none;" unselectable="on" class="ui-icon ui-icon-closethick">close</span>';
    $html .= '          </a>';
    $html .= '        <div class="form-item" id="edit-wo-common-name-'.$i.'-wrapper">';
    $html .= '          <div style="width:140px; float: left;">';
    $html .= '            <label for="edit-wo-common-name-'.$i.'" class="same-line">';
    $html .= '              ' .  t('Common Name') . ': ';
    $html .= '              <span class="form-required" title="' .  t('This field is required.') . '">*</span>';
    $html .= '            </label>';
    $html .= '          </div>';
    $html .= '          <div>';
    $html .= '            <input type="text" maxlength="128" name="wo_common_name_'.$i.'" id="edit-wo-common-name-'.$i.'" size="30" value="' . $cn . '" class="form-text required" />';
    $html .= '          </div>';
    $html .= '          <div class="description">' .  t('Enter common name.') . '</div>';
    $html .= '        </div>';
    $html .= '';
    $html .= '        <div class="form-item" id="edit-wo-common-name-language-'.$i.'-wrapper">';
    $html .= '          <div style="width:140px; float: left;">';
    $html .= '            <label for="edit-wo-common-name-language-'.$i.'" class="same-line">' .  t('Language of common name') . ': </label>';
    $html .= '          </div>';
    $html .= '          <div>';
    //$html .= '          <input type="text" maxlength="128" name="wo_common_name_language_'.$i.'" id="edit-wo-common-name-language-'.$i.'" size="30" value="' . $cnl . '" class="form-text" />';
    $html .= '            <select name="wo_common_name_language_'.$i.'" class="form-select" id="edit-wo-common-name-language-'.$i.'" >';
    $html .= '              ' .  createDropDownOptionsForCommonName($cn_languages, $cn_info, 'cn_language') . '';
    $html .= '            </select>';
    $html .= '          </div>';
    $html .= '          <div class="description">' .  t('Enter the language of the common name.') . '</div>';
    $html .= '        </div>';
    $html .= '';
    $html .= '        <div class="form-item" id="edit-wo-common-name-region-'.$i.'-wrapper">';
    $html .= '          <div style="width:140px; float: left;">';
    $html .= '            <label for="edit-wo-common-name-region-'.$i.'" class="same-line">' .  t('Region') . ': ';
    $html .= '              <span class="form-required" title="' .  t('This field is required.') . '">*</span>';
    $html .= '             </label>';
    $html .= '          </div>';
    $html .= '          <div>';
    $html .= '            <input type="text" maxlength="128" name="wo_common_name_region_'.$i.'" id="edit-wo-common-name-region-'.$i.'" size="30" value="' . $cnr . '" class="form-text" />';
    $html .= '          </div>';
    $html .= '          <div class="description">' .  t('Enter the region where the common name is used.') . '</div>';
    $html .= '        </div>';
    $html .= '';
    $html .= '        <div class="form-item" id="edit-wo-common-name-gender-'.$i.'-wrapper">';
    $html .= '          <div style="width:140px; float: left;">';
    $html .= '            <label for="edit-wo-common-name-gender-'.$i.'" class="same-line">' .  t('Gender') . ': </label>';
    $html .= '          </div>';
    $html .= '          <div>';
    $html .= '            <select name="wo_common_name_gender_'.$i.'" class="form-select" id="edit-wo-common-name-gender-'.$i.'" >';
    $html .= '              ' .  createDropDownOptionsForCommonName($gender_options, $cn_info, 'gender') . '';
    $html .= '            </select>';
    $html .= '          </div>';
    $html .= '          <div class="description">' .  t('Please select the gender of specimen.') . '</div>';
    $html .= '        </div>';
    $html .= '';
    $html .= '        <div class="form-item" id="edit-wo-lifestage-'.$i.'-wrapper">';
    $html .= '          <div style="width:140px; float: left;">';
    $html .= '            <label for="edit-wo-lifestage-'.$i.'" class="same-line">' .  t('Life Stage') . ': </label>';
    $html .= '          </div>';
    $html .= '          <div>';
    $html .= '            <select name="wo_common_name_lifestage_'.$i.'" class="form-select" id="edit-wo-common-name-lifestage-'.$i.'" >';
    $html .= '              ' .  createDropDownOptionsForCommonName($lifestage_list, $cn_info, 'lifestage') . '';
    $html .= '            </select>';
    $html .= '          </div>';
    $html .= '          <div class="description">' .  t('Enter the lifestage of the specimen observed.') . '</div>';
    $html .= '        </div>';
    $html .= '';
    $html .= '        <div class="form-item" id="edit-wo-common-name-english-'.$i.'-wrapper" '.$show_spell.'>';
    $html .= '          <div style="width:140px; float: left;">';
    $html .= '            <label for="edit-wo-common-name-english-'.$i.'" class="same-line">';
    $html .= '              ' .  t('English Spelling of Common Name') . ': ';
    $html .= '              <span class="form-required" title="' .  t('This field is required.') . '">*</span>';
    $html .= '              <span class="formInfo"><a href="'.$base_path.'observation/tooltip/common_name_english?width=375" class="jTip" id="tooltip_common_name_english_'.$i.'" name="English Spelling of Common Name:">?</a></span>';
    $html .= '            </label>';
    $html .= '          </div>';
    $html .= '          <div>';
    $html .= '            <input type="text" maxlength="128" name="wo_common_name_english_'.$i.'" id="edit-wo-common-name-english-'.$i.'" size="30" value="' . $cne . '" class="form-text required alpha_space" />';
    $html .= '          </div>';
    $html .= '          <div class="description">' .  t('Please enter the english spelling of the common name.') . '</div>';
    $html .= '        </div>';
    $html .= '      </fieldset>';
  }

  if ($cnt == 0) {
    $cnt = 1;
  }
  drupal_add_js('commonNamesCount = ' . $cnt, 'inline');

  return $html;
}

function createDropDownOptionsForCommonName($arr, $cn_info, $type) {
  $options = '';
  if (count($arr) > 0) {
    if ($cn_info == NULL) {
      foreach ($arr as $id => $name) {
        $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
      }
    }
    else {
      switch ($type) {
        case 'cn_language':
        case 'gender':
        case 'lifestage':
          foreach ($arr as $id => $name) {
            if ($name == $cn_info[$type]) {
              $options .= '<option title="'.t($name).'" value="'.$id.'" selected="selected">'.t($name).'</option>';
            }
            else {
              $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
            }
          }
          break;
        default:
          foreach ($arr as $id => $name) {
            $options .= '<option title="'.t($name).'" value="'.$id.'">'.t($name).'</option>';
          }
          break;
      }
    }
  }
  return $options;
}